package presentation;

import java.util.List;
import org.hibernate.*;

import db.*;

public class Get16AlbumsBean {
	private Session session = null;
	private List<Album> albums;
	private long page;
	
	public Get16AlbumsBean() {
		 this.session = DbUtils.startSession();
		 this.albums = DbUtils.get16Albums(session, 1);
	}
	
	public Get16AlbumsBean(int pageNumber) {
		 this.session = DbUtils.startSession();
		 this.albums = DbUtils.get16Albums(session, pageNumber);
	};

	public List<Album> getPictures() {
		return albums;
	}

	public void releaseResources() {
		if(this.session != null) {
			this.session.close();
		}
	}
	

	public  List<Album> getUserAlbums(long userId) {
		 this.session = DbUtils.startSession();
		 List<Album> albums=DbUtils.getUserAlbums(session, userId);
		 return albums;
	}

	
	public long getAllAlbumsNum(long userId) {
		 this.session = DbUtils.startSession();
		 List<Album> albums=DbUtils.getUserAlbums(session, userId);
		long allAlb=albums.size();
	if(allAlb<16){
			page=1;
	} else{
		 if(allAlb%16!=0){
				page=(allAlb/16)+1;
		 }else{
				page=(allAlb/16);
		 }
	}
		 return page;
		
	}
	
	public List<Album>getAllAlbums() {
		 this.session = DbUtils.startSession();
		List<Album> albums= DbUtils.getAllAlbums(session);
		 return albums;	
	}
}

